package eva.savant.business.administrador.view

import eva.savant.core.view.Bean
import eva.savant.businessobject.ad.Transaccion

import javax.faces.bean.ManagedBean
import javax.faces.bean.SessionScoped
import javax.annotation.PostConstruct

@SessionScoped
@ManagedBean(name = 'IMTransaccion')
public class IMTransaccion extends Bean {

  @PostConstruct
  public void cleanEntity() {

    lsEntity= new ArrayList<Transaccion>()
  }

  public List findLsEntity() {

    return find(Transaccion.class,'sistema.id=?',sistema.id)
  }

  public void removeEntity(Object entity) {

    remove(entity)
  }

  public void updTransacion() {

    readFilePackage('transaccion.txt').eachLine { line ->

    def val= line.split(':')

    def type= val[2].startsWith('IM')? 1 : val[2].startsWith('IT')? 2 : 3


    merge(new Transaccion(sociedad.id + val[0], sistema, val[0],  val[3],

                          '/business/'+ val[1] + '/' + val[2] + '.xhtml',

                          type, ALTA, sociedad.id, usuario.id))
    }

  }

}